package logic

import (
	"github.com/fastknifes/usdt-pay/internal/repository/dao"
	"github.com/fastknifes/usdt-pay/internal/repository/model/entity"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
)

type NotifyLogic struct{}

func (n *NotifyLogic) TriggerCallBack(trade entity.Trade) bool {
	ctx := gctx.New()
	response, _ := g.Client().Post(
		ctx,
		trade.Callback,
		trade,
	)

	if response.StatusCode != 200 {
		return false
	}

	result := response.ReadAllString()

	if result == "ok" {
		dao.Trade.Ctx(ctx).Where("id", trade.Id).Delete()
		return true
	}
	return false

}
